#include "login.h"
#include "ui_login.h"
#include <qdebug.h>


login::login(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::login)
{
    ui->setupUi(this);
}

login::~login()
{

    delete ui;
}

void login::on_lineEdit_editingFinished()
{
    if(sql.open("data") == false)
    {
        QString str = "CREATE DATABASE data";
        sql.exec(str);
        qDebug()<<"创建了数据库"<<Qt::endl;
    }
    QString str1 = "CREATE TABLE IF NOT EXISTS login_infom ("
                   "id INTEGER PRIMARY KEY AUTOINCREMENT,"
                   "number VARCHAR(50),"
                   "pwd INTEGER,"
                   "pixmap VARCHAR(50))";
    sql.exec(str1);
    qDebug()<<"输入完成，加载图片"<<Qt::endl;
    text = ui->lineEdit->text();
    QString str = "SELECT * FROM login_infom WHERE number = '%1'";
    if(sql.exec(str.arg(text)) != NULL)
    {
        pQuery = sql.exec(str.arg(text));
        pQuery->next();
        map_inform = pQuery->value(3).toString();
        if(pixmap.load(map_inform) == false)
        {
            qDebug()<<"加载"<<map_inform<<"失败"<<Qt::endl;
        }
        ui->label_3->setScaledContents(true);
        ui->label_3->setPixmap(pixmap);
    }
}


void login::on_pushButton_clicked()
{
    QString text1 = ui->lineEdit_2->text();
    pwd = pQuery->value(2).toString();
    QString number = pQuery->value(1).toString();
    if(pwd == text1 && number == text)
    {
        qDebug()<<"登陆成功"<<Qt::endl;
        sendpixmap(map_inform);
        this->hide();
    }
    else
    {
        qDebug()<<"登陆失败"<<Qt::endl;
    }
}

void login::sendpixmap(QString pixmap_inform)
{
    emit sendParameter(pixmap_inform);
}
